﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Web;
using Jumbot.Common;
using Jumbot.DataOper;

namespace JumbotCms.DataObject
{
    /// <summary>
    /// 频道表信息
    /// </summary>
    public class Channel
    {
        private string m_Id = "0";
        private string m_Title = string.Empty;
        private string m_Dir = string.Empty;
        private bool m_Enabeld;
        private string m_Info;
        private string m_Type = "system";
        private int m_PId;
        private string m_ItemName;
        private string m_ItemUnit;
        private int m_TemplateId;
        private bool m_IsNav;
        private bool m_IsHtml = false;
        private bool m_IsOut;
        private string m_OutUrl;
        private bool m_Target;
        private int m_ClassDepth;

        public string Id
        {
            get { return m_Id; }
            set { m_Id = value; }
        }
        /// <summary>
        /// 频道名称
        /// </summary>
        public string Title
        {
            set { m_Title = value; }
            get { return m_Title; }
        }
        /// <summary>
        /// 频道路径
        /// </summary>
        public string Dir
        {
            set { m_Dir = value; }
            get { return m_Dir; }
        }
        public bool Enabled
        {
            set { m_Enabeld = value; }
            get { return m_Enabeld; }
        }
        public string Info
        {
            set { m_Info = value; }
            get { return m_Info; }
        }
        /// <summary>
        /// 频道类型
        /// </summary>
        public string Type
        {
            set { m_Type = value; }
            get { return m_Type; }
        }
        public int PId
        {
            get { return m_PId; }
            set { m_PId = value; }
        }
        /// <summary>
        /// 频道项目名称
        /// </summary>
        public string ItemName
        {
            set { m_ItemName = value; }
            get { return m_ItemName; }
        }
        /// <summary>
        /// 频道项目单位
        /// </summary>
        public string ItemUnit
        {
            set { m_ItemUnit = value; }
            get { return m_ItemUnit; }
        }
        public int TemplateId
        {
            get { return m_TemplateId; }
            set { m_TemplateId = value; }
        }
        /// <summary>
        /// 是否导航
        /// </summary>
        public bool IsNav
        {
            set { m_IsNav = value; }
            get { return m_IsNav; }
        }
        /// <summary>
        /// 是否生成静态
        /// </summary>
        public bool IsHtml
        {
            set { m_IsHtml = value; }
            get { return m_IsHtml; }
        }
        public bool IsOut
        {
            set { m_IsOut = value; }
            get { return m_IsOut; }
        }
        public string OutUrl
        {
            set { m_OutUrl = value; }
            get { return m_OutUrl; }
        }
        public bool Target
        {
            set { m_Target = value; }
            get { return m_Target; }
        }
        /// <summary>
        /// 频道的栏目最大深度
        /// </summary>
        public int ClassDepth
        {
            get { return m_ClassDepth; }
            set { m_ClassDepth = value; }
        }
        public Channel() { }
        public void GetAllColumn(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT * FROM [jcms_normal_channel] WHERE id=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                Id = _id;
                Title = dr["Title"].ToString();
                Dir = dr["Dir"].ToString();
                Enabled = dr["Enabled"].ToString() == "1";
                Info = dr["Info"].ToString();
                Type = dr["Type"].ToString().ToLower();
                PId = Validator.StrToInt(dr["PId"].ToString(), 0);
                ItemName = dr["ItemName"].ToString();
                ItemUnit = dr["ItemUnit"].ToString();
                TemplateId = Validator.StrToInt(dr["TemplateId"].ToString(), 0);
                IsNav = dr["IsNav"].ToString() == "1";
                IsHtml = dr["IsHtml"].ToString() == "1";
                IsOut = dr["IsOut"].ToString() == "1";
                OutUrl = dr["OutUrl"].ToString();
                Target = dr["Target"].ToString() == "1";
                ClassDepth = Validator.StrToInt(dr["ClassDepth"].ToString(), 0);
            }
            else
            {
                Id = "0";
            }
        }
        /// <summary>
        /// 取部分字段[Id],[Type],[Dir]
        /// </summary>
        /// <param name="_id"></param>
        /// <param name="doh"></param>
        public void GetPartColumn(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [Type],[Dir] FROM [jcms_normal_channel] WHERE id=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                Id = _id;
                Dir = dr["Dir"].ToString();
                Type = dr["Type"].ToString().ToLower();
            }
            else
            {
                Id = "0";
            }
        }
        public string GetTitle(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [Title] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0]["Title"].ToString();
            }
            return string.Empty;
        }
        public string GetDir(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [Dir] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0]["Dir"].ToString();
            }
            return string.Empty;
        }
        public int GetEnabled(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [Enabled] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return Validator.StrToInt(dt.Rows[0]["Enabled"].ToString(), 0);
            }
            return 0;
        }
        public string GetInfo(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [Info] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0]["Info"].ToString();
            }
            return string.Empty;
        }
        public string GetType(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [Type] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0]["Type"].ToString().ToLower();
            }
            return string.Empty;
        }
        public int GetPId(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [PId] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return Validator.StrToInt(dt.Rows[0]["PId"].ToString(), 0);
            }
            return 0;
        }
        public string GetItemName(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [ItemName] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0]["ItemName"].ToString();
            }
            return string.Empty;
        }
        public string GetItemUnit(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [ItemUnit] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0]["ItemUnit"].ToString();
            }
            return string.Empty;
        }
        public int GetTemplateId(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [TemplateId] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return Validator.StrToInt(dt.Rows[0]["TemplateId"].ToString(), 0);
            }
            return 0;
        }
        public int GetIsNav(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [IsNav] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return Validator.StrToInt(dt.Rows[0]["IsNav"].ToString(), 0);
            }
            return 0;
        }
        public int GetIsHtml(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [IsHtml] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return Validator.StrToInt(dt.Rows[0]["IsHtml"].ToString(), 0);
            }
            return 0;
        }
        public int GetIsOut(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [IsOut] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return Validator.StrToInt(dt.Rows[0]["IsOut"].ToString(), 0);
            }
            return 0;
        }
        public string GetOutUrl(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [OutUrl] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return dt.Rows[0]["OutUrl"].ToString();
            }
            return string.Empty;
        }
        public int GetTarget(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [Target] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return Validator.StrToInt(dt.Rows[0]["Target"].ToString(), 0);
            }
            return 0;
        }
        public int GetClassDepth(string _id, DbOperHandler doh)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [ClassDepth] FROM [jcms_normal_channel] WHERE [Id]=" + _id;
            DataTable dt = doh.GetDataTable();
            if (dt.Rows.Count > 0)
            {
                return Validator.StrToInt(dt.Rows[0]["ClassDepth"].ToString(), 0);
            }
            return 0;
        }
    }
}
